package org.wiztools.te.plugin;

import org.wiztools.te.TEMod;
import org.wiztools.te.TEProcess;

public class HTMLize implements TEProcess{

	private TEMod tem;
	
	public void init(){
		// do nothing!
	}
	
	public void setTEMod(TEMod tem){
		this.tem = tem;
	}
	
	private String convertToHTML(String t){
		if(t==null){
			return "";
		}
		t = t.replaceAll("\\&", "&amp;");
		t = t.replaceAll("<", "&lt;");
		t = t.replaceAll(">", "&gt;");
		t = t.replaceAll("\"", "&quot;");
		return t;
	}
	
	public void action(){
		tem.replaceSelection(convertToHTML(tem.getSelectedText()));
	}
	
	public void destroy(){
		// do nothing!
	}
}
